<template ref="import">
  <el-dialog
    title="选择人员"
    :visible.sync="visible"
    width="50%"
  >
    <div style="display: flex;">
      <div>
      </div>
      <div style="display: flex;"><span
        style="margin-left: 10px;display:inline-block;width: 100px;line-height: 35px;font-weight:700">员工姓名</span>
        <el-input v-model="two" placeholder="请输入内容"></el-input>
        <el-button style="margin-left: 5px;height: 40px" size="mini" type="primary" @click="searchfn">搜索</el-button>
        <el-button style="" size="mini" type="primary" @click="chongzhifn">重置</el-button>
      </div>
    </div>

<!--    <div style="display: flex;width: 100%;justify-content: space-between">-->
<!--&lt;!&ndash;        <el-table&ndash;&gt;-->
<!--&lt;!&ndash;          :data="deptList"&ndash;&gt;-->
<!--&lt;!&ndash;          row-key="deptId"&ndash;&gt;-->
<!--&lt;!&ndash;          :default-expand-all="isExpandAll"&ndash;&gt;-->
<!--&lt;!&ndash;          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"&ndash;&gt;-->
<!--&lt;!&ndash;          @cell-click="cellfn"&ndash;&gt;-->
<!--&lt;!&ndash;        >&ndash;&gt;-->
<!--&lt;!&ndash;          <el-table-column prop="deptName" label="部门名称" ></el-table-column>&ndash;&gt;-->
<!--&lt;!&ndash;        </el-table>&ndash;&gt;-->

<!--      <div style="width: 80%">-->
        <el-table
          @cell-click="dianjifn"
          :data="list"
        >
          <el-table-column
            prop="name"
            label="姓名"
          >
          </el-table-column>
          <el-table-column
            prop="deptName"
            label="部门"
          >
          </el-table-column>
          <el-table-column
            prop="telephone"
            label="手机号码">
          </el-table-column>

        </el-table>
<!--      </div>-->
<!--    </div>-->

    <div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="unit">
      </el-pagination>
    </div>

    <span slot="footer" class="dialog-footer">
    <el-button @click="visible = false">取 消</el-button>
    <el-button type="primary" @click="visible = false">确 定</el-button>
  </span>
  </el-dialog>
</template>

<script>
import {listDept} from "@/api/system/dept"

export default {
  name:"elselect",
  props:{
    list:{
      type:Array,
    }

  },
  data() {
    return {
      //分页的总共多少条数据
      unit:"",
      //分页当前第几页
      currentPage4: 1,
      visible: false,
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 表格树数据
      deptList: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      one: "",
      two: "",
      tableData: [],
      //部门名
      department:"部门选择",
    // 字典部门
      bumen:""
    }
  },
  created() {
    this.getDictionary()
  },
  methods: {
    handleNodeClick(data) {
      console.log(data);
    },
    // 显示弹框
    show() {
      this.visible = true;
     // this.unit=10
      console.log(this.list)

    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.$emit('meiye',val)

    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.$emit('dangqian',val)
    },
    //获取部门数据
    async getDictionary() {
     const {data:res}= await listDept()
      this.deptList = this.handleTree(res, "deptId");
      this.loading = false;
    },
    //组件搜索
    searchfn(){
      this.$emit('serch',this.two)
      // this.deptList.map(item=>)


    },
    //组件重置功能
    chongzhifn(){
      this.$emit('chongzhi')
      this.two=''
    },
    //点击table 栏列表 触发事件
    dianjifn(row){
      // console.log(row)
      this.$emit('anme',row)
      this.currentPage4=1

    },
    cellfn(row){
      // console.log(row)
    const res =  this.list.filter(item=>{
        return  item.deptName===row.deptName
      })
      // console.log(res)
      this.list = res
    }

  }
};
</script>
